<?php
$params = array_merge(
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/menu.php')
);

$d = '<dir:admin|site|api>';
$c = '<controller:[\w-]+>';
$a = '<action:[\w-]+>';

$config = [
    'id' => 'application',
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'vendorPath' => dirname(__DIR__) . '/vendor',
    'modules' => [
        'markdown' => [
            'class' => 'kartik\markdown\Module',
        ],
    ],
    'components' => [
        'request' => [
            'enableCsrfValidation' => true,
            'enableCookieValidation' => false,
            'csrfParam' => '_csrf_application',
        ],
        'user' => [
            'class' => 'yii\web\User',
            'identityClass' => 'mz\models\UserModel.bak',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-site', 'httpOnly' => true],
        ],
        'admin' => [
            'class' => 'yii\web\User',
            'identityClass' => 'mz\models\AdminModel',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-admin', 'httpOnly' => true],
            'loginUrl' => '/admin/login'
        ],
        'session' => [
            // this is the name of the session cookie used for login on the frontend
            'name' => 'mzcms-application',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error/index',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                $d                                               =>'<dir>/index/index',
                $d . '/' . $c                                    => '<dir>/<controller>/index',
                $d . '/' . $c . '/' . $a                         => '<dir>/<controller>/<action>',
            ],
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
    ],
    'defaultRoute' => 'site/index/index',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'mz\controllers',
    'runtimePath' => __DIR__ . 'runningtime/cmslogs/',
    'params' => $params

];

if(preg_match('#(admin)\/#',$_SERVER['REQUEST_URI']) > 0)
{
    $config['components']['errorHandler'] = [
        'errorAction' => 'admin/error/index',
    ];
}

if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['127.0.0.1'],
        'generators' => []
    ];
}

return $config;
